var dayjs = require("dayjs");
// arg表示原始参数,num表示小数点位,默认保留两位,symbol表示符号（￥,$）,spilt是否进行逗号分隔【true，false】
const priceFormat = (arg, num = 0, symbol, spilt = false) => {
  arg = Number(arg).toFixed(num);
  if (spilt == true) {
    if (arg.indexOf(".") == -1) {
      arg = arg.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    } else {
      var parts = arg.split(".");
      parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
      arg = parts.join(".");
    }
  }

  if (symbol) {
    arg = symbol + arg;
  }
  return arg;
};
// 时间过滤器
const timeFormat = (time, format) => {
  if (time) {
    return dayjs(time).format(format);
  } else {
    return time;
  }
};
const imgFormat = (img, isCar) => {
  if (isCar) {
    if (!img || img === BASE_URL) {
      // return require("@/static/images/common/car.png");
    }
    return img;
  } else {
    if (!img || img === BASE_URL) {
      return require("@/static/image/defaultAvatar.png");
    }
    return img;
  }
};

export {
  priceFormat,
  timeFormat,
  imgFormat
};
